package artid.com.arttogo.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.adapter.DotPraiseUser_Adapter;
import artid.com.arttogo.bean.DotPraiseUserParser;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;
import artid.com.arttogo.view.pulllist.PullToRefreshLayout;
import artid.com.arttogo.view.pulllist.PullableListView;

/**
 * 
*    
* 项目名称：ArtworkArt   
* 类名称：DotPraiseUser_Activity   
* 类描述：点赞用户   
* 创建人：耿卫斌   
* 创建时间：2017-1-18 上午10:36:05   
*
 */
public class DotPraiseUser_Activity extends BaseActivity implements OnClickListener {
	private Context mContext;
	private PullableListView mListView;
	private PullToRefreshLayout mPullLayout;
	private boolean isRefreshed = false;// 是否刷新
	private int page = 1;
	private LinearLayout noDataLL;//无数据布局
	private DotPraiseUser_Adapter adapter;
	private List<DotPraiseUserParser> list;
	private List<DotPraiseUserParser> more_list;
	private String art_id="55326";//艺术品ID
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_dotpraiseuser);
		mContext = DotPraiseUser_Activity.this;
		art_id = getIntent().getExtras().getString("id");
		initView();
	}

	private void initView() {
		list=new ArrayList<DotPraiseUserParser>();
		more_list=new ArrayList<DotPraiseUserParser>();
		mBack = (ImageView) findViewById(R.id.back_btn);
		mBack.setVisibility(View.VISIBLE);
		mBack.setOnClickListener(this);
		mTittle = (TextView) findViewById(R.id.tittle_text);
		mTittle.setText("点赞用户");
		noDataLL = (LinearLayout) findViewById(R.id.ll_hint);
		mListView = (PullableListView) findViewById(R.id.DotPraiseUser_ListView);
		mPullLayout = (PullToRefreshLayout) findViewById(R.id.DotPraiseUser_refresh_view);
		mPullLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {

			@Override
			public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
				// TODO Auto-generated method stub
				// 下拉刷新
				page = 1;
				isRefreshed = true;
				getData();
			}

			@Override
			public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
				// TODO Auto-generated method stub
				// pullToRefreshLayout.setBottomDismiss();
				// 上拉加载
				page++;
				getData();
			}
		});
		getData();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back_btn:
			// 返回
			finish();
			break;

		default:
			break;
		}
	}
	
	private void getData(){
		VolleyBasic.getInstance(this).post(
				Cache.artSupportList,
				VolleyMap.getInstance()
				.artSupportList(page, 10, art_id),
				DotPraiseUserParser.class, new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						mPullLayout.loadmoreFinish(mPullLayout.SUCCEED);
						list = (List<DotPraiseUserParser>) vd.getList();
						if (isRefreshed == true) {
							more_list.clear();
							isRefreshed = false;
						}
						if (!list.isEmpty()) {
							more_list.addAll(list);
						}
						// 这里是显示有数据和无数据的布局
						if (more_list != null && more_list.size() != 0) {
							 noDataLL.setVisibility(View.GONE);
						} else {
							 noDataLL.setVisibility(View.VISIBLE);
							return;
						}
						if (adapter == null) {
							adapter = new DotPraiseUser_Adapter(mContext, more_list);
							mListView.setAdapter(adapter);
						}
						adapter.notifyDataSetChanged();
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub
						mPullLayout.loadmoreFinish(mPullLayout.FAIL);
						// 这里是显示有数据和无数据的布局
						if (more_list != null && more_list.size() != 0) {
							 noDataLL.setVisibility(View.GONE);
						} else {
							 noDataLL.setVisibility(View.VISIBLE);
							return;
						}
					}
				});
	}
}
